package com.crape.message.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.crape.common.exceptions.DAOException;
import com.crape.common.ibatis.SqlMapClientDaoSupportEx;
import com.crape.common.model.MsgNotice;
import com.crape.message.dao.IMsgNoticeDAO;

@Service
public class MsgNoticeDAOImpl extends SqlMapClientDaoSupportEx implements IMsgNoticeDAO {

    @Override
    public MsgNotice getMsgOutboxById(Long id) throws DAOException {
        if (id == null) {
            return null;
        }
        return (MsgNotice) this.queryObject("getMsgOutboxById", id);
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<MsgNotice> getPagedMsgOutboxBySid(Long accountid, Integer state, Integer startIndex, Integer pageSize)
                                                                                                                     throws DAOException {
        if (accountid == null || startIndex == null || pageSize == null || pageSize == 0) {
            return null;
        }
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("accountid", accountid);
        params.put("state", state);
        params.put("startIndex", startIndex);
        params.put("pageSize", pageSize);
        return (List<MsgNotice>) this.queryList("getPagedMsgOutboxBySid", params);
    }

    @Override
    public void insertMsgOutbox(MsgNotice msgOutbox) throws DAOException {
        if (msgOutbox == null) {
            return;
        }
        this.insert("insertMsgOutbox", msgOutbox);
    }

    @Override
    public void updateMsgOutbox(MsgNotice msgOutbox) throws DAOException {
        if (msgOutbox == null) {
            return;
        }
        this.update("insertMsgOutbox", msgOutbox);
    }

    @Override
    public void deleteMsgOutboxById(Long id) throws DAOException {
        if (id == null) {
            return;
        }
        this.delete("deleteMsgOutboxById", id);
    }

}
